import 'package:flutter/material.dart';

class MyHomePage extends StatefulWidget {
  MyHomePage({Key key, this.title}) : super(key: key);

  final String title;

  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {

  String value;

  void _gotoA() {
    Navigator.pushNamed(context, '/a');
  }

  void _gotoB() {
    Navigator.pushNamed(context, '/b');
  }

  void _gotoC() {
    Navigator.pushNamed(context, '/c');
  }

  void _gotoD() {
    final value = Navigator.push(context,
        MaterialPageRoute(
            builder: (BuildContext context) => MyPage(title: 'Page D')));
    print('value =  $value ');
  }

  void _gotoE() async {
    bool value = await Navigator.push(context,
        MaterialPageRoute<bool>(
            builder: (BuildContext context) =>
                Scaffold(
                  appBar: new AppBar(
                    title: new Text("navigator can return a value"),),
                  body: GestureDetector(
                    child: new RaisedButton(
                      onPressed: null,
                      child: new Text('OK',),
                      disabledColor: Colors.blue,
                    ),
                    onTap: () {
                      Navigator.pop(context, true);
                    },
                    onDoubleTap: () => Navigator.pop(context, false),
                  ),
                )
        )
    );
    print('value =  $value ');
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            ButtonBar(
              children: <Widget>[
                new RaisedButton(onPressed: _gotoA, child: new Text('Page A'),),
                new RaisedButton(onPressed: _gotoB, child: new Text('Page B')),
                new RaisedButton(onPressed: _gotoC, child: new Text('Page C')),
//                new RaisedButton(onPressed: _gotoC, child: new Text('Page D')),
              ],
            ),
            ButtonBar(
              children: <Widget>[
                new RaisedButton(onPressed: _gotoD, child: new Text('Page D')),
                new RaisedButton(onPressed: _gotoE, child: new Text('Page E')),
              ],
            ),
          ],
        ),
      ),
    );
  }
}


class MyPage extends StatelessWidget {

  MyPage({this.title});

  final String title;

  @override
  Widget build(BuildContext context) {
    return new Scaffold(
      appBar: new AppBar(
        title: Text(this.title),
      ),
      body: new Column(
          children: <Widget>[
            new Text(this.title,
              style: new TextStyle(fontWeight: FontWeight.w500,
                  fontSize: 26,
                  color: Colors.blue),
            ),
            new RaisedButton(onPressed: () => Navigator.pop(context),
              child: new Text('back to Home'),
            )
          ]
      ),
    );
  }
}